package com.sgcc.sx.pmos.e_sx_mall.presenter;

import android.text.TextUtils;

import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.sx.pmos.common.base.BasePresenter;
import com.sgcc.sx.pmos.common.bean.PowMonth;
import com.sgcc.sx.pmos.common.utils.UserManager;
import com.sgcc.sx.pmos.e_sx_mall.contract.PowSetTotalContract;

import java.math.BigDecimal;
import java.util.List;

public class PowSetTotalPresenter extends BasePresenter<PowSetTotalContract.View> implements PowSetTotalContract.Presenter {
    @Override
    public void getGoodsList(int pageSize, boolean isLoading) {

    }

    public static boolean checkPowList(List<PowMonth> list) {
        boolean haveNull = false;
        for (int i = 0; i < list.size(); i++) {
            if (TextUtils.isEmpty(list.get(i).getREnergy())) {
                ToastUtils.showShort("请将数据填写完整");
                haveNull = true;
                break;
            }
        }
        return haveNull;
    }
    private String convertDoubleToString(String num) {
        BigDecimal bd = new BigDecimal(num);
        return bd.setScale(3, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();

    }
    public String getTotalTipick(List<PowMonth> list) {
        if (!TextUtils.isEmpty(UserManager.getUserBean().getEnergyHis())) {
            double oldPow = Double.valueOf(UserManager.getUserBean().getEnergyHis());
            String totalTipicStr = "";
            if (list != null && list.size() != 0) {
                for (int i = 0; i < list.size(); i++) {
                    double nowPow = Double.valueOf(list.get(0).getREnergy());
                    if (nowPow > 1.2 * oldPow || nowPow < 0.8 * oldPow) {
                        totalTipicStr = totalTipicStr + list.get(i).getMonthDate() + "月你的输入的约定量总量是" + convertDoubleToString(nowPow+"") + "MWh,与去年月均用电量悬殊较大，请确认。\n";
                    }
                }
            } else {
                return "";
            }
            if (!TextUtils.isEmpty(totalTipicStr)) {
                return "你去年的历史月均用电量是" + oldPow + "MWh。\n" + totalTipicStr;
            } else {
                return "";
            }
        } else {
            return "";
        }
    }
}
